package com.shuyi.webhook.qywx;

import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.api.WxCpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description
 * @Author yangyidian
 * @Date 2023/03/31
 * @Version 0.1.0
 **/
@Component
@Slf4j
public class QyWxNotifyApplication {

    @Autowired
    private WxCpProperties wxCpProperties;

    public void sendText(String message) {
        this.sendText(message, wxCpProperties.getWebhookConfig().getMobileList());
    }

    public void sendText(String message, List<String> phones) {
        try {
            final WxCpService wxCpService = WxCpConfiguration.getCpService(1);
            wxCpService.getGroupRobotService().sendText(wxCpProperties.getWebhookConfig().getUrl(), message, null, phones);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
